/**
 初始化 公司信息

 **/

(function (vc) {
    vc.extends({
        data: {
            storeTypes: [],
            companyBaseInfo: {
                name: "",
                shopName:'',
                areaAddress: '',
                address: "",
                tel: "",
                storeTypeCd: "800900000005",
                nearbyLandmarks: "无",
                areaCode:'',
                shopType:'',
                shopTypes:[],
            },
            areas: [],
            provs: [],
            citys: [],
            selectProv: '',
            selectCity: '',
            selectArea:'',
            allCity: []
        },
        _initMethod: function () {

            $that._initArea('101', '0');
            $that._listShopTypes();
        },
        _initEvent: function () {

        },
        watch: {
            companyBaseInfo: {
                deep: true,
                handler: function () {
                    //$that.$emit('companyBaseEvent', $that.companyBaseInfo);
                    vc.emit('company','notifyCompanyInfo',$that.companyBaseInfo);
                }
            }
        },
        methods: {
            getProv: function (_prov) {
                $that._initArea('202', _prov);
            },
            getCity: function (_city) {
                $that._initArea('303',_city);
            },
            getArea: function (_area) {
                $that.companyBaseInfo.areaAddress = '';
                if (!$that.provs) {
                    return;
                }
                $that.provs.forEach(function (_param) {
                    if (_param.areaCode == $that.selectProv) {
                        $that.companyBaseInfo.areaAddress = _param.areaName;
                    }
                });

                $that.citys.forEach(function (_param) {
                    if (_param.areaCode == $that.selectCity) {
                        $that.companyBaseInfo.areaAddress += _param.areaName;
                    }
                });
                $that.areas.forEach(function (_param) {
                    if (_param.areaCode == $that.selectArea) {
                        $that.companyBaseInfo.areaAddress += _param.areaName;
                    }
                });
                $that.companyBaseInfo.areaCode = _area;
            },
            _initArea: function (_areaLevel, _parentAreaCode) { //加载区域
                var _param = {
                    params: {
                        areaLevel: _areaLevel,
                        parentAreaCode: _parentAreaCode
                    }
                };
                vc.http.get('company', 'getAreas',
                    _param,
                    function (json, res) {
                        if (res.status == 200) {
                            var _tmpAreas = JSON.parse(json);
                            if (_areaLevel == '101') {
                                $that.provs = _tmpAreas;
                            } else if (_areaLevel == '202') {
                                $that.citys = _tmpAreas;
                            } else {
                                $that.areas = _tmpAreas;
                            }
                            return;
                        }
                        //$that.$emit('errorInfoEvent',json);
                    }, function (errInfo, error) {
                        console.log('请求失败处理', errInfo, error);
                        vc.toast("查询地区失败");
                    });
            },
            _listShopTypes: function () {
                var param = {
                    params: {
                        page: 1,
                        row: 100,
                    }
                };
                //发送get请求
                vc.http.apiGet('/shopType.queryShopType',
                    param,
                    function (json, res) {
                        let _shopTypeManageInfo = JSON.parse(json);
                        $that.companyBaseInfo.shopTypes = _shopTypeManageInfo.data;
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
        }

    });

})(window.vc);

